<template> 
		<view class="uni-common-mt">
			<view class="uni-form-item uni-column fg">
				<view class="title">商品名称</view>
				<input class="uni-input" placeholder="请输入商品名称" v-model="model.mc" />
			</view>

			<view class="uni-form-item uni-column fg">
				<view class="title">置顶</view>
				<radio-group name="radio" @change="zdChange">
					<label>
						<radio value="1" :checked="model.zd ==1" /><text>置顶</text>
					</label>
					<label>
						<radio value="0" :checked="model.zd ==0" /><text>不置顶</text>
					</label>
				</radio-group>
			</view>
			
			<view class="uni-form-item uni-column fg">
				<view class="title">是否上架</view>
				<view>
					<switch name="switch" :checked="model.sj==1" />
				</view>
			</view>

			<view class="uni-form-item uni-column fg">
				<view class="title">开卖日期</view>
				<picker mode="date" :value="model.smrq" start="1950-09-01" end="2123-09-01" @change="dateChange">
					<view class="picker">
						{{model.smrq || "2023-06-18"}}
					</view>
				</picker>
			</view>

			<view class="uni-form-item uni-column fg">
				<view class="title">商品分类</view>
				<picker :value="model.fl" :range="fls"  @change="pickerChange" >
					<view class="picker">
						{{model.fl || "数码"}}
					</view>
				</picker>
			</view>

			<view class="uni-form-item uni-column">
				<view class="title">商品描述</view>
				<view class="uni-textarea">
					<textarea v-model="model.nr" />
				</view>
			</view>

			<view class="uni-btn-v">
				<button type="primary" @tap="save">保存</button>
			</view>
			
			<view class="uni-btn-v">
				<button type="warn" @tap="qc">清除缓存</button>
			</view>
			
		</view> 
</template>

<script>
	export default {
		data() {
			return {
				model: {
					zd: 0,
					sj: 1,
					fl: "数码",
					nr: '商品介绍。。。'
				},
				fls: ["数码", "食品", "服装"]
			}
		},
		onLoad() {
			this.initData();
		},
		methods: {
			initData() {
				const cacheData = uni.getStorageSync("gs1")
				if (cacheData != "") {
					this.model = cacheData;
				}
			},
			zdChange(e) {
				this.model.zd = e.detail.value
			},
			pickerChange(e) {
				this.model.fl = this.fls[e.detail.value];
			},
			dateChange(e) {
				this.model.smrq = e.detail.value;
			},
			save() {
				console.log(this.model);
				uni.setStorageSync("gs1", this.model)
				uni.getStorageInfo({
					success: function (res) {
						console.log(res.keys);
						console.log(res.currentSize);
						console.log(res.limitSize);
					}
				});
			},
			qc(){
				uni.removeStorageSync("gs1");
			}
		}
	}
</script>

<style> 
	button {
		margin-top: 10px;
	}
	
	.fg {
		border-bottom: solid 1px orangered;
	}
</style>